#!/bin/bash

echo "copy PGDATA"
cd $PGDATA
cd ..
path=$(pwd)
dn=$(basename "$PGDATA")
mv ${dn} ${dn}_bak
echo "successfully copy PGDATA"

echo "starting dssserver"
dssserver -M -D $DSS_HOME > $DSS_HOME/startdss.log 2>&1 &
sleep 3
echo "successfully start dssserver"

echo "starting initdb"
cd $GAUSSLOG/om
initdb_str=$(grep gs_init *)
initdb_str2=$(echo "$initdb_str" | grep -o 'gs_initdb.*')
eval "${initdb_str2}"
echo "successfully initdb"

echo "restore PGDATA"
rm -rf $PGDATA
cd $path
mv ${dn}_bak ${dn}
echo "successfully restore PGDATA"
